package com.atom.process.cnmuseum.bm.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.impl.util.json.JSONArray;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.atom.common.entity.RunningTaskDO;
import com.atom.common.remote.user.UserUtil;
import com.atom.common.web.controller.AbstractMainController;
import com.atom.process.cnmuseum.bm.dao.task.BmTaskDao;
import com.atom.process.cnmuseum.bm.entity.task.BmTaskDO;
import com.atom.process.cnmuseum.bm.render.BMRender;
import com.atom.process.cnmuseum.bm.service.BianmuService;
import com.atom.process.cnmuseum.bm.service.CangPinService;
import com.atom.process.cnmuseum.bm.service.LuruService;
import com.atom.process.cnmuseum.bm.service.NeiRongShenheService;
import com.atom.process.cnmuseum.bm.service.ServiceInterface;
import com.atom.process.cnmuseum.bm.service.TaskListService;
import com.atom.process.cnmuseum.bm.service.ZiYuanShenheService;
import com.atom.process.cnmuseum.bm.tool.PageUtils;
import com.atom.process.cnmuseum.bm.tool.ProcessDefinitions;
import com.atom.process.cnmuseum.bm.tool.TaskDefinitions;
import com.atom.process.cnmuseum.bm.vo.QueryVO;
import com.atom.process.cnmuseum.bm.vo.request.DbrwRequestVO;
import com.atom.process.cnmuseum.bm.vo.request.GcxxRequestVO;
import com.atom.process.cnmuseum.bm.vo.request.RequestVO;
import com.atom.process.cnmuseum.bm.vo.request.WhrlxxxRequestVO;
import com.atom.process.cnmuseum.bm.vo.request.WhsxRequestVO;
import com.atom.process.cnmuseum.bm.vo.request.XzxxRequestVO;
import com.atom.process.cnmuseum.bm.vo.request.YxxxRequestVO;
import com.atom.process.cnmuseum.bm.vo.response.ResponseVO;
import com.atom.process.cnmuseum.cj.vo.request.MultimediaRequestVO;
import com.atom.process.cnmuseum.cj.vo.request.TrackmessageRequestVO;
import com.atom.process.cnmuseum.cj.vo.request.XzyxRequestVO;
import com.sinosoft.cnmuseum.utils.Status;
import com.sinosoft.cnmuseum.utils.StringUtils;
import com.sinosoft.commontools.record.Record;

@Controller
@RequestMapping("bm")
public class MainController extends AbstractMainController {

	private static Logger logger = Logger.getLogger(MainController.class);

	private static final String VIEW_PREFIX = "bm/";
	private static final String DIAGRAM_VIEW = "contractFlowChart";
	private static final String LOG_VIEW = "log";

	/**
	 * Description: 暂存
	 * 
	 * @param processDefinitionId
	 * @return
	 */
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	@ResponseBody
	public String save(@ModelAttribute RequestVO vo,
			@ModelAttribute GcxxRequestVO gcxxvo,
			@ModelAttribute XzxxRequestVO xzxxvo,
                       @ModelAttribute YxxxRequestVO yxxxvo,
                       @ModelAttribute WhrlxxxRequestVO whrlxxxvo,
			HttpServletRequest request) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		try {
			UserUtil user = new UserUtil(request);
			String taskid = vo.getTaskId();
			String taskDefKey = "";
			// 获取流程
			if (StringUtils.isEmpty(taskid)) {// 未创建流程，县创建流程，在保存
				// 创建流程
				String taskId = bianmuService.create(user, gcxxvo.getCollection_code());
				// 获取流程参数
				ResponseVO newvo = render.getDetail(taskId, user);
				// 设置流程参数
				vo.setTaskId(newvo.getVo().getTaskId());
				vo.setProcessId(newvo.getVo().getProcessId());
				// 设置流程步骤
				taskDefKey = TaskDefinitions.编目.getKey();
			} else {// 已创建流程，直接保存
				List<RunningTaskDO> lists = taskListService.getRunningTaskListByTaskId(taskid);
				taskDefKey = lists.get(0).getTaskDefinitionKey();
			}
			// 保存
			ServiceInterface service = getService(taskDefKey);
            service.save(vo, gcxxvo, xzxxvo, yxxxvo, whrlxxxvo,user);
			Record record = new Record();
			record.add(Status.SATUS,Status.OK);
			return record.toJsonStr();
		} catch (Exception e) {
			logger.error("error message = {}" + e.getMessage(), e);
			Record record = new Record();
			record.add(Status.SATUS,Status.FAILED);
			return record.toJsonStr();
		}
	}

	/**
     * Description: 获取详细信息
     *
     * @param taskId
     * @param request
     * @return
     */
    @RequestMapping(value = "/commentlist", method = RequestMethod.GET)
    @ResponseBody
    public String getCommentList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        String taskId = params.getTask_id();
        BmTaskDO bm = bmTaskDao.findByTaskId(taskId);
        return super.getCommentByTaskId(bm.getProcessId());
    }

    /**
	 * Description: 提交
	 * 
	 * @param processDefinitionId
	 * @return
	 */
	@RequestMapping(value = "/submit", method = RequestMethod.POST)
	@ResponseBody
	public String submit(@ModelAttribute RequestVO vo, 
			@ModelAttribute GcxxRequestVO gcxxvo,
                         @ModelAttribute XzxxRequestVO xzxxvo,
                         @ModelAttribute YxxxRequestVO yxxxvo,
                         @ModelAttribute WhrlxxxRequestVO whrlxxxvo,
                         HttpServletRequest request) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		try {
			UserUtil user = new UserUtil(request);
			String taskid = vo.getTaskId();
			String taskDefKey = "";
			// 获取流程
			if (StringUtils.isEmpty(taskid)) {// 未创建流程，县创建流程，再提交
				// 创建流程
				String taskId = bianmuService.create(user, gcxxvo.getCollection_code());
				// 获取流程参数
				ResponseVO newvo = render.getDetail(taskId, user);
				// 设置流程参数
				vo.setTaskId(newvo.getVo().getTaskId());
				vo.setProcessId(newvo.getVo().getProcessId());
				// 设置流程步骤
				taskDefKey = TaskDefinitions.编目.getKey();
			} else {// 已创建流程，直接提交
				List<RunningTaskDO> lists = taskListService.getRunningTaskListByTaskId(taskid);
				taskDefKey = lists.get(0).getTaskDefinitionKey();
			}
			// 提交
			ServiceInterface service = getService(taskDefKey);
            service.save(vo, gcxxvo, xzxxvo, yxxxvo, whrlxxxvo,user);
            vo.setBiaoti("编目_"+gcxxvo.getCollection_code());
			service.submit(vo,user);
			Record result = new Record();
			result.add(Status.SATUS, Status.OK);
			return result.toJsonStr();
		} catch (Exception e) {
			logger.error("error message = {}" + e.getMessage(), e);
			Record result = new Record();
			result.add(Status.SATUS, Status.FAILED);
			return result.toJsonStr();
		}
	}

	/**
	 * Description: 新建
	 * 
	 * @return
	 */
	@RequestMapping(value = "create", method = RequestMethod.GET)
	@ResponseBody
	public String create(HttpServletRequest request,
			@RequestParam(value = "gcxxid", required = true) String gcxxid) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		UserUtil user = new UserUtil(request);
		ResponseVO vo = new ResponseVO();
		try {
			String taskId = bianmuService.create(user, gcxxid);
			vo = render.getDetail(taskId, user);
			vo.setTaskDefKey(TaskDefinitions.编目.getKey());
			vo.setStatus(1);

			Record data = new Record();
			data.add("task_id", taskId);
			Record result = new Record();
			result.add("data", data);
			result.add(Status.SATUS, Status.OK);
			return result.toJsonStr();
			
		} catch (Exception e) {
			logger.error("error message = {}" + e.getMessage(), e);
			Record result = new Record();
			result.add(Status.SATUS, Status.FAILED);
			return result.toJsonStr();
		}
	}

	/**
	 * Description: 删除
	 * 
	 * @param processDefinitionId
	 * @return
	 */
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public String delete(@ModelAttribute RequestVO vo,
			HttpServletRequest request) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		try {
			UserUtil user = new UserUtil(request);
			bianmuService.delete(vo, user);
			Record result = new Record();
			result.add(Status.SATUS, Status.OK);
			return result.toJsonStr();
		} catch (Exception e) {
			logger.error("error message = {}" + e.getMessage(), e);
			Record result = new Record();
			result.add(Status.SATUS, Status.FAILED);
			return result.toJsonStr();
		}
	}
/**
	 * Description: 获取列表
	 * 
	 * @param taskId
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/bmlist", method = RequestMethod.GET)
	@ResponseBody
	public String getList(@ModelAttribute QueryVO params,
			HttpServletRequest request) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		return service.getList(params,request).toJsonStr();
	}
	/**
	 * Description: 获取详细信息
	 * 
	 * @param taskId
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getdetail", method = RequestMethod.GET)
	@ResponseBody
	public String getDetail(@ModelAttribute QueryVO params,
			HttpServletRequest request) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		return service.getDetail(params.getTask_id()).toJsonStr();
	}
    /**
     * Description: 代表人物
     *
     * @param taskId
     * @param request
     * @return
     */
    @RequestMapping(value = "/dbrwlist", method = RequestMethod.GET)
    @ResponseBody
    public String getDbrwList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getDbrwList(params.getTask_id()).toJsonStr();
    }

    @RequestMapping(value = "/dbrwdetail", method = RequestMethod.GET)
    @ResponseBody
    public String getDbrwDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getDbrwDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/savedbrw", method = RequestMethod.POST)
    @ResponseBody
    public String saveDbrw(@ModelAttribute DbrwRequestVO dbrwvo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveDbrw(dbrwvo,user).toJsonStr();
    }
    @RequestMapping(value = "/deletedbrw", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String deleteDbrw(@RequestParam("zdbh") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteDbrw(id,user).toJsonStr();
    }
    

    /**
     * 多媒体信息
     */
    @RequestMapping(value = "/multimedialist", method = RequestMethod.GET)
    @ResponseBody
    public String getMultimediaList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getMultimediaList(params.getTask_id()).toJsonStr();
    }

    @RequestMapping(value = "/multimediadetail", method = RequestMethod.GET)
    @ResponseBody
    public String getMultimediaDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getMultimediaDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/savemultimedia", method = RequestMethod.POST)
    @ResponseBody
    public String saveMultimedia(@ModelAttribute MultimediaRequestVO multimediavo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveMultimedia(multimediavo,user).toJsonStr();
    }
    @RequestMapping(value = "/deletemultimedia", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String deleteMultimedia(@RequestParam("zdbh") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteMultimedia(id,user).toJsonStr();
    }
    
    /**
     * 曲目信息
     */
    @RequestMapping(value = "/trackmessagelist", method = RequestMethod.GET)
    @ResponseBody
    public String getTrackmessageList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getTrackmessageList(params.getTask_id()).toJsonStr();
    }

    @RequestMapping(value = "/trackmessagedetail", method = RequestMethod.GET)
    @ResponseBody
    public String getTrackmessageDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getTrackmessageDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/savetrackmessage", method = RequestMethod.POST)
    @ResponseBody
    public String saveTrackmessage(@ModelAttribute TrackmessageRequestVO trackmessagevo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveTrackmessage(trackmessagevo,user).toJsonStr();
    }
    @RequestMapping(value = "/deletetrackmessage", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String deleteTrackmessage(@RequestParam("zdbh") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteTrackmessage(id,user).toJsonStr();
    }
    /**
     * 形制文件信息
     */
    
    @RequestMapping(value = "/xzwjxxlist", method = RequestMethod.GET)
    @ResponseBody
    public String getXzwjxxList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getXzyxList(params.getTask_id(),"xz").toJsonStr();
    }

    @RequestMapping(value = "/xzwjxxdetail", method = RequestMethod.GET)
    @ResponseBody
    public String getXzwjxxDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getXzyxDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/savexzwjxx", method = RequestMethod.POST)
    @ResponseBody
    public String saveXzwjxx(@ModelAttribute XzyxRequestVO xzyxvo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveXzyx(xzyxvo,user,"xz").toJsonStr();
    }
    @RequestMapping(value = "/deletexzwjxx", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String deleteXzwjxx(@RequestParam("zdbh") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteXzyx(id,user,"xz").toJsonStr();
    }
    
    
    /**
     * 音响文件信息
     */
    
    @RequestMapping(value = "/yxwjxxlist", method = RequestMethod.GET)
    @ResponseBody
    public String getYxwjxxList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getXzyxList(params.getTask_id(),"xz").toJsonStr();
    }

    @RequestMapping(value = "/yxwjxxdetail", method = RequestMethod.GET)
    @ResponseBody
    public String getYxwjxxDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getXzyxDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/saveyxwjxx", method = RequestMethod.POST)
    @ResponseBody
    public String saveYxwjxx(@ModelAttribute XzyxRequestVO xzyxvo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveXzyx(xzyxvo,user,"yx").toJsonStr();
    }
    @RequestMapping(value = "/deleteyxwjxx", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String deleteYxwjxx(@RequestParam("zdbh") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteXzyx(id,user,"yx").toJsonStr();
    }
    
    
    
    
    
    
    /**
     * Description: 文化事项
     *
     * @param taskId
     * @param request
     * @return
     */
    @RequestMapping(value = "/whsxlist", method = RequestMethod.GET)
    @ResponseBody
    public String getWhsxList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getWhsxList(params.getTask_id()).toJsonStr();
    }

    @RequestMapping(value = "/whsxdetail", method = RequestMethod.GET)
    @ResponseBody
    public String getWhsxDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getWhsxDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/savewhsx", method = RequestMethod.POST)
    @ResponseBody
    public String saveWhsx(@ModelAttribute WhsxRequestVO whsxvo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveWhsx(whsxvo,user).toJsonStr();
    }
    @RequestMapping(value = "/deletewhsx", method = RequestMethod.GET)
    @ResponseBody
    public String deleteWhsx(@RequestParam("id") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteWhsx(id,user).toJsonStr();
    }
    
    /**
	 * Description: 查看待办详细
	 * 
	 * @param taskDefKey
	 * @param taskId
	 * @return
	 */
	@RequestMapping(value = "/detail/{taskDefKey}/{taskId}", method = RequestMethod.GET)
	public String getDetail(@PathVariable("taskDefKey") String taskDefKey,
			@PathVariable("taskId") String taskId, HttpServletRequest request) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		UserUtil user = new UserUtil(request);

		String view = VIEW_PREFIX;
		// if (TaskDefinitions.编目申请.equal(taskDefKey) ||
		// TaskDefinitions.部门主任审核.equal(taskDefKey)) {
		// view = view + "xiuGaiBianMuShenQing";
		// } else {
		// view = view + "xiuGaiBianMuShenHe";
		// }
		if (TaskDefinitions.编目.equal(taskDefKey)) {
			view = view + "caiji";
		} else if (TaskDefinitions.录入.equal(taskDefKey)) {
			view = view + "luru";
		} else if (TaskDefinitions.内容审核.equal(taskDefKey)) {
			view = view + "neirongshenhe";
		} else if (TaskDefinitions.资源审核.equal(taskDefKey)) {
			view = view + "ziyuanshenhe";
		}

		ResponseVO vo = new ResponseVO();
		try {
			vo = render.getDetail(taskId, user);
			vo.setTaskDefKey(taskDefKey);
			vo.setStatus(1);
		} catch (Exception e) {
			vo.setStatus(0);
		}
		return vo.toString();
		// return new ModelAndView(view, "data",
		// JsonUtil.ObjectToJsonQuietly(vo));
	}

	/**
	 * Description: 查看流程图
	 * 
	 * @param mainProcessInstanceId
	 * @return
	 */
	@RequestMapping(value = "/diagram/{mainProcessInstanceId}", method = RequestMethod.GET)
	public ModelAndView getDiagram(
			@PathVariable("mainProcessInstanceId") String mainProcessInstanceId,
			HttpServletResponse response, HttpServletRequest request) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		return super.getDiagram(mainProcessInstanceId,
				ProcessDefinitions.PROCESS_DEF_KEY, VIEW_PREFIX + DIAGRAM_VIEW,
				response);
	}

	/**
	 * Description: 查看已办详细
	 * 
	 * @param taskId
	 * @return
	 */
	@RequestMapping(value = "/history/{taskId}", method = RequestMethod.GET)
	public void getHistory(@PathVariable("taskId") String taskId,
			HttpServletResponse response, HttpServletRequest request) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		try {
			super.getHistory(taskId, response);
		} catch (Exception e) {
			logger.error("error message = {}" + e.getMessage(), e);
		}
	}

	/**
	 * Description: 查看操作日志
	 * 
	 * @param mainProcessInstanceId
	 * @return
	 */
	@RequestMapping(value = "/log/{mainProcessInstanceId}", method = RequestMethod.GET)
	public ModelAndView getLog(
			@PathVariable("mainProcessInstanceId") String mainProcessInstanceId,
			HttpServletResponse response, HttpServletRequest request) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		return super.getLog(mainProcessInstanceId, LOG_VIEW, response);
	}

	
	@RequestMapping(value = "getRunningTaskListJson", method = RequestMethod.GET)
	@ResponseBody
	public String getRunningTaskListJson(HttpServletRequest request) {
		logger.info("REQUEST: " + request.getRequestURL().toString());
		UserUtil user = new UserUtil(request);
		int pagenumber = 1;
		int pagesize = 10;
		String taskDefinitionKey = request.getParameter("taskdefkey");
		String titlename = request.getParameter("titlename");
		try {
			String pagenumberstr = request.getParameter("pagenumber");
			pagenumber = Integer.parseInt(pagenumberstr);
		} catch (Exception e) {
		}
		try {
			String pagesizestr = request.getParameter("pagesize");
			pagesize = Integer.parseInt(pagesizestr);
		} catch (Exception e) {
		}
		List<Object> rlist = new ArrayList<Object>(); 
		Map<String, Object> result = new HashMap<String, Object>();
		List<RunningTaskDO> list = null;
		try {
			int total = taskListService.getRunningTaskCount(user, titlename, taskDefinitionKey);
			PageUtils pageutil = new PageUtils(pagenumber, pagesize, total);
			list = taskListService.getRunningTaskList(user, titlename,taskDefinitionKey, pageutil.getStart(), pageutil.getPagesize());

			result.put(Status.ROWS, list);
			result.put(Status.TOTAL, total);
			result.put(Status.CODE, Status.CODE_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			result.put(Status.CODE, Status.CODE_ERROR);
		}
		rlist.add(result);
		JSONArray array = new JSONArray(rlist);
		String ss = array.toString();
		//String ss = JsonUtil.ObjectToJsonQuietly(result);
		return ss.substring(1, ss.length()-1);
	}

	/*-------------------------------------------------------------------------------------------------------------
	 * 
	 * 
	 * 
	 */

	private ServiceInterface getService(String taskDefKey) {
		if (TaskDefinitions.编目.equal(taskDefKey)) {
			return bianmuService;
		}
		if (TaskDefinitions.录入.equal(taskDefKey)) {
			return luruService;
		}
		if (TaskDefinitions.内容审核.equal(taskDefKey)) {
			return nrshService;
		}

		if (TaskDefinitions.资源审核.equal(taskDefKey)) {
			return zyshService;
		}

		return null;
	}

	@Resource
	BianmuService bianmuService;
	@Resource
	LuruService luruService;
	@Resource
	NeiRongShenheService nrshService;
	@Resource
	ZiYuanShenheService zyshService;

	@Resource
	BMRender render;
	@Resource
	CangPinService service;

	@Resource
	BmTaskDao bmTaskDao;
	@Resource
	TaskListService taskListService;

}
